package com.ticket.sass.admin.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.AppBusiness;
import com.ticket.sass.admin.business.impl.AppBusinessImpl;
import com.ticket.sass.admin.dto.input.feature.AppEnableInput;
import com.ticket.sass.admin.dto.output.feature.AppListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 功能相关表 前端控制器
 * </p>
 *
 * @author ywb
 * @since 2024-03-15
 */
@RestController
@ApiSupport(order = 7)
@RequestMapping("/apps")
@Api(tags = {"应用中心-模块"})
public class AppController {
    final AppBusiness business;
    
    public AppController(AppBusinessImpl business) {
        this.business = business;
    }
    
    @GetMapping
    @ApiOperation("列表")
    public ResultModel<PageModel<AppListOutput>> list(
    
    ) {
        return ResultModel.success(
            business.list()
        );
    }
    
    @GetMapping("/{type}")
    @ApiOperation("app具体信息")
    public ResultModel<AppListOutput> show(
        @Valid @PathVariable Short type
    ) {
        return ResultModel.success(business.info(type));
    }
    
    @Loggable(module = Module.CONFIG, desc = "设置启用")
    @PutMapping("/enable")
    @ApiOperation("设置启用")
    public ResultModel<String> setEnable(
        @RequestBody AppEnableInput input
    ) {
        business.setEnable(input);
        return ResultModel.success();
    }
}
